<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.0/css/jquery.dataTables.css"></link>
<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="/js/jquery.leanModal.min.js"></script>
<script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" language="javascript" src="//cdn.datatables.net/1.10.0/js/jquery.dataTables.js"></script>
<style type="text/css">
.loader {
	position: fixed;
	left: 0px;
	top: 0px;
	width: 100%;
	height: 100%;
	z-index: 9999;
	background-image:"/images/3.gif";
	background: 50% 50% no-repeat rgb(249,249,249);
}
</style>
<script type="text/javascript" language="javascript">
$(window).load(function() {
	$(".loader").fadeOut("slow");
})

jQuery.fn.dataTableExt.oApi.fnGetHiddenNodes = function ( settings )
{
    var nodes;
    var display = jQuery('tbody tr', settings.nTable);
 
    if ( jQuery.fn.dataTable.versionCheck ) {
        // DataTables 1.10
        var api = new jQuery.fn.dataTable.Api( settings );
        nodes = api.rows().nodes().toArray();
    }
    else {
        // 1.9-
        nodes = this.oApi._fnGetTrNodes( settings );
    }
 
    /* Remove nodes which are being displayed */
    for ( var i=0 ; i<display.length ; i++ ) {
        var iIndex = jQuery.inArray( display[i], nodes );
 
        if ( iIndex != -1 ) {
            nodes.splice( iIndex, 1 );
        }
    }
 
    return nodes;
};

$(document).ready(function() {
	oTable = $('#product_table').dataTable({
        "lengthMenu": [[-1], ["All"]]
    });
	} );
function tickAll(source){
	if(source.checked){
		$('.tick').prop('checked',true);
		var changeValue = $("#selectAll").val();
		$('.tick').each(function () {
		    var idCheck = this.id;
		    if($("#"+idCheck).prop('checked')){
			
				var idSp = idCheck.split("_");
				$("#action_" + idSp[1] + " option[value = " + changeValue + " ]").attr('selected',true);
		    }
		});
	}else{
		$('.tick').prop('checked',false);
	}

}

function changeOption(source){
	
	

}
	
</script>

</head>

<body>
<div style="font-family:Arial, Helvetica, sans-serif;" >
<h1>Stock Review</h1>
<?php $reviewType = unserialize(REVIEW_TYPE);?>
<h3>Period: <?php echo $this->dateStart?> ~~ <?php echo $this->dateEnd?></h3>


<?php $product = new Model_DbTable_Productsva();?>

<?php if($this->rateInput == true){?>
		
<select id = "selectAll" style = "margin-left:500px">
			<option selected="selected"  value = "" disabled>Please Select</option>
			<option value = "1" >Reviewed(1)</option>
			<option value = "2" >Discount(2)</option>
			<option value = "3" >Clearance(3)</option>
			<option value = "4" >Disposal(4)</option>
			<option value = "5" >Never Review</option>
		</select>	
<input type = "checkbox" id = "tickAll"  onclick = "tickAll(this)"></input>Tick ALL
<?php }?>

<form id="form1" name="form1" method="post" action="" enctype="multipart/form-data">
<?php if($this->rateInput == true){
		$rate = ($this->rate)/100;?>
		

<table width = "1000" border="1" cellspacing="1" cellpadding="5" id="product_table">
<thead> 
	<tr>
		<th>No.</th>
		<th>Barcode</th>
		<th>Intro Date(Barcode)</th>
		<th>Description</th>
		<th>Shop Qty</th>
		<th>WH Qty</th>
		<th>GN Qty</th>
		<th>Total Stock Qty</th>
		<th>Sales Total</th>
		<th>RRP</th>
		<th>Rate &lt; <?php echo $this->rate;?>%</th>
		<th>Action</th>
		<th></th>
		<th>Last Status</th>
		<th>Last Review Date</th>
	</tr> </thead>
<tbody>
	<?php $i = 0;?>
	<?php foreach ($this->arrStock as $k => $v){
			$i++;
			$pDetail = $product->getProductByBarcode($v['product_barcode']);
		
			$totalQty = $v['shop_stock']+ $v['wh_stock'] + $v['grn_total'];
			if($v['sales_total'] == 0){
				$result = 'No Sale';
			}else{
				if($totalQty != 0){
					$result = $v['sales_total']/$totalQty;
				}else{
					$result = 'No Stock';
				}
			}
			
			
		?>
	<tr>
		<td><?php echo $i;?></td>
		<td><?php echo $v['product_barcode']?></td>
		<td><?php echo $pDetail['date_introduce']?></td>
		<td><?php echo $pDetail['title_product']?></td>
		<td><?php echo $v['shop_stock']?></td>
		<td><?php echo $v['wh_stock']?></td>
		<td><?php echo $v['grn_total']?></td>
		<td><?php echo $totalQty?></td>
		<td><?php echo $v['sales_total']?></td>
		<td><?php echo $v['rrp'];?></td>
		<td <?php if($result < $rate){?>bgcolor="#FF0000"<?php }?>><?php if($result == 'No Stock' || $result == 'No Sale'){echo $result;}elseif($result < $rate){echo 'Below';}else{echo 'Above';}?></td>
		<td><select name = "action[<?php echo $v['product_barcode']?>]" id = "action_<?php echo $i?>"  class = "test">
			<option selected="selected" disabled>Please Select</option>
			<option value = "1" <?php if($pDetail['review_action'] > 1){?>disabled<?php }?>>Reviewed(1)</option>
			<option value = "2" <?php if($pDetail['review_action'] > 2){?>disabled<?php }?>>Discount(2)</option>
			<option value = "3" <?php if($pDetail['review_action'] > 3){?>disabled<?php }?>>Clearance(3)</option>
			<option value = "4" >Disposal(4)</option>
			<option value = "5" >Never Review</option>
		</select></td>
		<td><input type = "checkbox" class = "tick" id = "tick_<?php echo $i?>"></input></td>
		<td><?php if(!empty($pDetail['review_action'])){echo $reviewType[$pDetail['review_action']][0].'('.$pDetail['review_action'].')';}?></td>
		<td><?php if(!empty($pDetail['review_action'])){echo $pDetail['review_date'];}?></td>
	</tr>
	
	<?php }?>
</tbody>
</table>
<?php if($this->reviewEnd != true){?>
<input type = "submit" name = "final_submit" value = "Confirm This Page Review"></input>
<?php }else{?>
<input type = "submit" name = "finish" value = "Check Result"></input>
<?php }?>
<?php }else{ ?>
	Please input sale rate<input type = "text" name = "rate" size = "3"></input>%<br/><br/>
	<input type = "submit" name = "submit" value = "Submit Rate"></input>
<?php }?>
<br />
<br />
</form>
</div>
<div style=" font-size:10px; color:#666;float:right;" >Developer:Leo,Date:2015-02-01,ver:1.01</div>
<div class="loader"></div>
</body>

</html>
